.DEFAULT_GOAL := help
.PHONY: help
help:
	@awk 'BEGIN { \
		FS = ":.*##"; \
		printf "\nUsage:\n  make \033[36m<target>\033[0m\n"\
	} \
	/^[a-zA-Z_-]+:.*?##/ { \
		printf "  \033[36m%-17s\033[0m %s\n", $$1, $$2 \
	} \
	/^##@/ { \
		printf "\n\033[1m%s\033[0m\n", substr($$0, 5) \
	} ' $(MAKEFILE_LIST)

##@ Dependencies

.PHONY: install
install:	## 初始化安装开发工具
	go install github.com/google/wire/cmd/wire@latest
	go install github.com/golang/mock/mockgen@latest
	go install github.com/cosmtrek/air@latest
	go install golang.org/x/tools/cmd/stringer@latest
	go install github.com/swaggo/swag/cmd/swag@latest

.PHONY: swag
swag: ## 更新swagger文档
	@echo "Running ${@}"
	swag init  --output=api_docs  --parseDependency --parseInternal --dir=./cmd/main,./internal

.PHONY: stringer
stringer: ## 更新错误码
	@echo "Running ${@}"
	stringer -type ErrCode -linecomment ./internal/errcode

.PHONY: wire
wire: ## wire更新
	@echo "Running ${@}"
	cd cmd/main/wire && wire && cd -

##@ Build

.PHONY: build
build: ## 编译构建api
	@echo "Running ${@}"
	./scripts/release.sh build -o ./bin/soutchat cmd/main/main.go cmd/main/config.go

.PHONY: build-linux
build-linux: ## 编译构建api-linux版本
	@echo "Running ${@}"
	CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ./scripts/release.sh build  -o ./bin/soutchat cmd/main/main.go cmd/main/config.go


.PHONY: build-test
build-test: ## 编译构建api-test,需要编译swagger
	@echo "Running ${@}"
	./scripts/release.sh build -tags swagger -race  -o ./bin/soutchat cmd/main/main.go cmd/main/config.go

.PHONY: build-test-linux
build-test-linux: ## 编译构建api-test-linux版本,需要编译swagger
	@echo "Running ${@}"
	CGO_ENABLED=0 GOOS=linux GOARCH=amd64 ./scripts/release.sh build -tags swagger -race -o ./bin/soutchat cmd/main/main.go cmd/main/config.go
